class Stack:    
    def __init__(self):    
        self.items = []    
    
    def is_empty(self):    
        return len(self.items) == 0    
    
    def push(self, item):    
        self.items.append(item)    
    
    def pop(self):    
        if self.is_empty():    
            raise IndexError("pop from empty stack")    
        return self.items.pop()    
    
    def peek(self):    
        if self.is_empty():    
            raise IndexError("peek from empty stack")    
        return self.items[-1]   
  
    def clear(self):  
        self.items = []   
    
    def size(self):    
        return len(self.items)   
  
def Calculate_score(input_list: list) -> int:  
    score = Stack()  
    for item in input_list:  
        # 通过for循环遍历模拟回合，根据规则制定分支语句 
        if item == 'C':  
            if not score.is_empty():  
                score.pop()  
        elif item == 'D':  
            if not score.is_empty():  
                score.push(2 * score.peek())  
        elif item == '+':  
            if score.size() >= 2:  
                score1 = score.pop()  
                score2 = score.peek()  
                score.push(score1) 
                score.push(score1 + score2)
        else: 
            score.push(int(item))
             
    return sum(score.items)  
  
# 测试代码  
print(Calculate_score(["5","2","C","D","+"]))
print(Calculate_score(["5","-2","4","C","D","9","+","+"]))
